package com.test.mybatis.entities;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.io.Serializable;
import java.util.List;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/11/7 11:29
 */
@Getter
@Setter
@NoArgsConstructor
public class Department implements Serializable {
    private static final long serialVersionUID = -2087721255408675361L;

    private Integer id;
    private String departmentName;
    private List<Employee> emps;

    public Department(Integer id, String departmentName) {
        this.id = id;
        this.departmentName = departmentName;
        if (this.id == 1) {
            this.departmentName = "开发部";
        } else if (this.id == 2) {
            this.departmentName = "测试部";
        }
    }

    @Override
    public String toString() {
        return "Department{" +
                "id=" + id +
                ", departmentName='" + departmentName + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Department that = (Department) o;

        return new EqualsBuilder()
                .append(id, that.id)
                .append(departmentName, that.departmentName)
                .isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37)
                .append(id)
                .append(departmentName)
                .toHashCode();
    }
}
